<?php

namespace plugin\kb_blog\common;

use support\view\Raw;

class View extends Raw
{
    /**
     * Render.
     * @param string $template
     * @param array $vars
     * @return false|string
     */
    public static function render(string $template, array $vars, string $app = null, string $plugin = null): string
    {
        $request = request();
        $__template_path__ = $template;

        if (isset($request->_view_vars)) {
            extract((array)$request->_view_vars);
        }
        extract($vars);
        ob_start();
        // Try to include php file.
        try {
            include $__template_path__;
        } catch (\Throwable $e) {
            ob_end_clean();
            throw $e;
        }

        return ob_get_clean();
    }
}
